package com.yan.thread;

/**
 * @author taoge
 * @Date 2024/8/7 16:05
 * @Description yield 让步方法
 */
public class ThreadDemo6 {
    public static void main(String[] args) {
        Thread t1 = new Thread(new MyTask6(), "线程A");
        t1.start();

        MyTask7 t2 = new MyTask7("--线程B");
        t2.start();
    }
}
class MyTask7 extends Thread{
    public MyTask7() {
    }

    public MyTask7(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 200; i < 300; i++) {
            Thread.yield();
            System.out.println(Thread.currentThread().getName() + "--" +i);
        }
    }
}
class MyTask6 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() +"--" + i);
        }
    }
}
